﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using JTLeigh.Commerce.Spencer.Features.ProductImages.Common.Entities;
using JTLeigh.Commerce.Spencer.Features.ProductImages.Business.Caches;

namespace JTLeigh.Commerce.Spencer.Features.ProductImages.Business.UnitTests.Caches
{

	/// <summary>
	/// Unit tests for the <see cref="InMemoryProductImageMetadataCache"/> class.
	/// </summary>
	[TestClass]
	public class InMemoryProductImageMetadataCacheFixture
	{

		#region Fields

		private static Guid TestTenant1Id = Guid.NewGuid();
		private static Guid TestTenant2Id = Guid.NewGuid();

		#endregion // Fields

		#region Methods

		#region ProductImageMetadata

		/// <summary>
		/// Ensures <see cref="InMemoryProductImageMetadataCache.GetProductImageMetadata"/> and
		/// <see cref="InMemoryProductImageMetadataCache.SetProductImageMetadata"/> get and set 
		/// image metadata in the cache as expected for multiple tenants.
		/// </summary>
		[TestMethod]
		public void TestGetSetProductImageMetadata()
		{
			InMemoryProductImageMetadataCache cache;
			ProductImageMetadata metadata1;
			ProductImageMetadata metadata2;

			cache = new InMemoryProductImageMetadataCache();
			Assert.IsNull(cache.GetProductImageMetadata(TestTenant1Id));
            Assert.IsNull(cache.GetProductImageMetadata(TestTenant2Id));

			metadata1 = new ProductImageMetadata();
			cache.SetProductImageMetadata(TestTenant1Id, metadata1);
			metadata2 = new ProductImageMetadata();
			cache.SetProductImageMetadata(TestTenant2Id, metadata2);
			Assert.AreSame(metadata1, cache.GetProductImageMetadata(TestTenant1Id));
			Assert.AreSame(metadata2, cache.GetProductImageMetadata(TestTenant2Id));
		}

		#endregion // ProductImageMetadata

		#endregion // Methods

	}

}
